package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//套餐模块
@RestController
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @Autowired
    private DishService dishService;

    //套餐列表
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(
        @RequestParam(name = "page",defaultValue = "1") Integer pageNum,
        @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize,
        String name){ //1.接收参数
        //2.调用service查询
      Page<Setmeal> page =  setmealService.findByPage(pageNum,pageSize,name);
        //3.返回结果
        return ResultInfo.success(page);
    }
    //新增套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal){ //1.接收新增
        //2.调用service新增
        setmealService.save(setmeal);
        //返回结果
        return ResultInfo.success();
    }
    //删除套餐
    @DeleteMapping("/setmeal")
    public ResultInfo deleteById(@RequestParam List<Long> ids){ //接收参数
        //调用service删除
        setmealService.deleteById(ids);
        //返回结果
        return ResultInfo.success();
    }
    //启售停售 (不用返回值)
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo updateStatus(@PathVariable Integer status,
                             @RequestParam List<Long> ids){
        //调用service
        setmealService.updateStatus(status,ids);
        //返回结果
        return ResultInfo.success();
    }
    //回显(需要返回值)
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable Long id){ //接收get请求
       //调用service
        Setmeal setmeal = setmealService.findById(id);
       //返回
        return ResultInfo.success(setmeal);
    }
    //修改套餐 (不用返回值)
    @PutMapping("/setmeal")
    public ResultInfo updateById(@RequestBody Setmeal setmeal){ //接收put请求
        //调用service修改
        setmealService.updateById(setmeal);
        //返回结果
        return ResultInfo.success();
    }
    /*//套餐添加菜品之模糊查询 (暂未使用)
    @GetMapping("/dish/")
    public ResultInfo findByName(String name){ //1.接收请求
        //2.调用service查询
        List<Dish> dishList = setmealService.findByName1(name);

        //返回结果
        return ResultInfo.success(dishList);
    }*/
}
